<?php

class Potentialactivity extends AppModel
{

    var $name = 'Potentialactivity';
    var $displayField = 'id';
    //The Associations below have been created with all possible keys, those that are not needed can be removed
    var $belongsTo = array(
        'Potential' => array(
            'className' => 'Potential',
            'foreignKey' => 'potential_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        ),
        'Activitytype' => array(
            'className' => 'Activitytype',
            'foreignKey' => 'activitytype_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        ),
        'Employee' => array(
            'className' => 'Employee',
            'foreignKey' => 'employee_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        ),
        'Assignedtoemployee' => array(
            'className' => 'Employee',
            'foreignKey' => 'assignedtoemployee_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );
    var $hasAndBelongsToMany = array(
        'Document' => array(
            'className' => 'Document',
            'joinTable' => 'potentialactivities_documents',
            'foreignKey' => 'potentialactivity_id',
            'associationForeignKey' => 'document_id',
            'unique' => true,
            'conditions' => '',
            'fields' => '',
            'order' => '',
            'limit' => '',
            'offset' => '',
            'finderQuery' => '',
            'deleteQuery' => '',
            'insertQuery' => ''
        )
    );
    var $validate = array(
        'potential_id' => array(
            'notEmpty' => array(
                'rule' => 'notEmpty',
                'allowEmpty' => false,
                'required' => true,
                'message' => 'Invalid potential'
            ),
            'numeric' => array(
                'rule' => 'numeric',
                'allowEmpty' => false,
                'required' => true,
                'message' => 'Invalid potential type'
            )
        ),
        'activitytype_id' => array(
            'notEmpty' => array(
                'rule' => 'notEmpty',
                'allowEmpty' => false,
                'required' => true,
                'message' => 'Please choose an activity type'
            ),
            'numeric' => array(
                'rule' => 'numeric',
                'allowEmpty' => false,
                'required' => true,
                'message' => 'Invalid activity type'
            )
        ),
        'subject' => array(
            'notEmpty' => array(
                'rule' => 'notEmpty',
                'allowEmpty' => false,
                'required' => true,
                'message' => 'Please enter activity subject'
            )
        ),
        'employee_id' => array(
            'notEmpty' => array(
                'rule' => 'notEmpty',
                'allowEmpty' => false,
                'required' => true,
                'message' => 'Invalid employee'
            ),
            'numeric' => array(
                'rule' => 'numeric',
                'allowEmpty' => false,
                'required' => true,
                'message' => 'Invalid employee type'
            )
        ),
        'assignedtoemployee_id' => array(
            'notEmpty' => array(
                'rule' => 'notEmpty',
                'allowEmpty' => false,
                'required' => true,
                'message' => 'Invalid assigned employee'
            ),
            'numeric' => array(
                'rule' => 'numeric',
                'allowEmpty' => false,
                'required' => true,
                'message' => 'Invalid assigned employee type'
            )
        )
    );

    function beforeSave()
    {
        parent::beforeSave();
        /*
         * format the nextfollowupdate and duedate column according to the yyyy-dd-mmy H:i:s format
         */
        if( !empty($this->data[$this->alias]['nextfollowupdate']) )
        {
            $this->data[$this->alias]['nextfollowupdate'] = date('Y-m-d H:i:s', strtotime($this->data[$this->alias]['nextfollowupdate']));
        }
        if( !empty($this->data[$this->alias]['duedate']) )
        {
            $this->data[$this->alias]['duedate'] = date('Y-m-d H:i:s', strtotime($this->data[$this->alias]['duedate']));
        }
        return true;
    }

}

?>